const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

function resolve(dir) {
  return path.join(__dirname, dir);
}

module.exports = {
  lintOnSave: true,
  baseUrl: './',
  productionSourceMap: process.env.NODE_ENV !== 'production',
  chainWebpack: (config) => {
    config.resolve.alias.set('@images', resolve('./src/assets/images'));
    config.resolve.alias.set('@svg', resolve('./src/icons/svg'));
    config.module.rules.delete('svg'); // 重点:删除默认配置中处理svg,
    config.module
      .rule('svg-sprite-loader')
      .test(/\.svg$/)
      .include
      .add(resolve('src/icons/svg')) // 处理svg目录
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]',
      });
  },
  configureWebpack: {
    ...(process.env.NODE_ENV === 'production' ? {
      optimization: {
        minimizer: [
          new UglifyJsPlugin({
            uglifyOptions: {
              compress: {
                warnings: false,
                drop_console: true, // console
                drop_debugger: true,
                pure_funcs: ['console.log'],
              },
            },
          }),
        ],
      },
    } : {}),
  },
  devServer: {
    proxy: {
      '/uapws/rest/': {
        target: 'http://220.178.235.60:7070/approve/',
        ws: true,
        changeOrigin: true,
      },
    },
  },
  css: {
    loaderOptions: {
      sass: {
        data: '@import "@/styles/base.scss";',
      },
    },
  },
  transpileDependencies: [
    // /\/node_modules\/echarts\//,
    'node_modules/vue-echarts-v3/src',
  ],
};
